<?php
/**
 * Creates and handles the directory shortcode.
 */
class DocCentre_Directory_Shortcode
{
	/**
	 * Reference to the DocCentre system object.
	 * 
	 * @var DocCentre
	 */
	protected $system;
	
	
	
	/**
	 * Creates and manages interaction for the Document Centre directory.
	 * 
	 * @param DocCentre $system
	 * @return DocCentre_Upload_Shortcode
	 */
	public function __construct(DocCentre $system)
	{
		$this->system = $system;
		
		add_shortcode('doccentre_directory', array($this, 'controller'));
	}
	
	
	/**
	 * Displays the directory.
	 * 
	 * @param mixed $attributes
	 * @param mixed $content = null
	 */
	public function controller($attributes, $content = null)
	{
		// Get a list of documents and display
		if (current_user_can('read'))
			return $this->system->load_template('directory', array(
				'docs' => $this->system->library->list_documents()
			));
			
		else return $this->system->load_template('no_directory');
	}
}